package com.itany.cloud.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Author:shixiaojun@itany.com
 * Date:2022/8/11 11:20
 * Version:1.0-SNAPSHOT
 * Description:
 */
@Configuration
public class GatewayConfig {

    @Bean
    public RouteLocator routeLocator(RouteLocatorBuilder builder){
        RouteLocatorBuilder.Builder routes = builder.routes();
        // 参数一:当前路由的id
        // 参数二:使用的是JDK8提供的Function类型,通过lambda表达式进行赋值
        // path:定义的访问地址
        // uri:转发的服务提供者地址
        return routes.route("news_route",r -> r.path("/guonei").uri("http://news.baidu.com/guonei")).build();
    }

    @Bean
    public RouteLocator routeLocator2(RouteLocatorBuilder builder){
        RouteLocatorBuilder.Builder routes = builder.routes();
        // 参数一:当前路由的id
        // 参数二:使用的是JDK8提供的Function类型,通过lambda表达式进行赋值
        // path:定义的访问地址
        // uri:转发的服务提供者地址
        return routes.route("art_route",r -> r.path("/art").uri("https://baike.baidu.com/art")).build();
    }

}
